package main

import "fmt"

func getCount(cur int, n int) int {
	i := cur
	j := i + 1
	count := 0
	for i < n {
		count += min(j-1, n) - i + 1
		i *= 10
		j *= 10
	}
	return count
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func findKthNumber(n int, k int) int {
	cur := 1
	for {
		count := getCount(cur, n)
		if k > count {
			k -= count
			cur += 1
		} else {
			if k > 1 {
				k--
				cur *= 10
			} else {
				break
			}
		}
	}
	return cur
}
func main() {
	r := findKthNumber(13, 4)
	fmt.Println(r)
}
